package ca.ericslandry.shared.domain;

import javax.persistence.Id;

/**
 * One shard belonging to the named counter.
 * 
 * An individual shard is written to infrequently to allow the counter in
 * aggregate to be incremented rapidly.
 * 
 * @author j.s@google.com (Jeff Scudder)
 * @author <a href="mailto:eric.s.landry@gmail.com">Eric Landry</a>
 *         (Objectified)
 */
public class DatastoreCounterShard {
	@Id
	Long id;
	Integer shardNumber;
	String counterName;
	Integer count;

	public DatastoreCounterShard(String counterName, int shardNumber) {
		this(counterName, shardNumber, 0);
	}

	public DatastoreCounterShard(String counterName, int shardNumber, int count) {
		this.counterName = counterName;
		this.shardNumber = new Integer(shardNumber);
		this.count = new Integer(count);
	}

	public void increment(int amount) {
		count = new Integer(count.intValue() + amount);
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getShardNumber() {
		return shardNumber;
	}

	public void setShardNumber(Integer shardNumber) {
		this.shardNumber = shardNumber;
	}

	public String getCounterName() {
		return counterName;
	}

	public void setCounterName(String counterName) {
		this.counterName = counterName;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}
}
